import { createSlice } from "@reduxjs/toolkit";

const userStore = createSlice({
	name: "user",
	// 数据状态
	initialState: {
		token: localStorage.getItem('token') || "",
		refresh_token: localStorage.getItem('refresh_token') || "",
		userInfo: null,
	},
	reducers: {
		setToken(state, action) {
			state.token = action.payload;
			localStorage.setItem("token", action.payload);
		},
		setTefresh_token(state, action) {
			state.refresh_token = action.payload;
			localStorage.setItem("refresh_token", action.payload);
		},
		setUserInfo(state, action) {
			state.userInfo = action.payload;
		},
	},
});

export const { setToken, setTefresh_token, setUserInfo } = userStore.actions;
export default userStore.reducer;
